package com.xxxx;

import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.ConnectedStreams;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.api.functions.co.CoMapFunction;

/**
 * 批量数据处理
 */
public class Hello08FlinkOperatorConnect {
    public static void main(String[] args) throws Exception {
        //创建环境
        StreamExecutionEnvironment environment = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(new Configuration());
        //获取数据源
        DataStreamSource<String> source1 = environment.fromElements("a", "bb", "ccc", "dddd");
        DataStreamSource<Integer> source2 = environment.fromElements(11, 22, 33, 44);
        //将两个类型不同的列拼接到一起
        ConnectedStreams<String, Integer> connectStream = source1.connect(source2);
        //对流进行处理
        connectStream.map(new CoMapFunction<String, Integer, String>() {
            @Override
            public String map1(String s) throws Exception {
                return "Str:".concat(s);
            }

            @Override
            public String map2(Integer num) throws Exception {
                return "Int:" + num;
            }
        }).print();

        //执行流
        environment.execute("Hello08FlinkOperatorConnect" + System.currentTimeMillis());

    }
}
